package com.song.web.controller;

import com.song.book.service.BookService;
import com.song.user.pojo.User;
import com.song.user.service.UserService;
import com.song.web.service.BookFeignService;
import com.song.web.service.SmsFeignService;
import com.song.web.service.UserFeignService;
import entity.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 宋伟宁
 * @Date 2024/1/5
 * @Version 1.0
 **/
@RestController
public class WebController {

    @Resource
    private BookFeignService bookFeignService;
    @Resource
    private UserFeignService userFeignService;

    @Resource
    private SmsFeignService smsFeignService;

    @GetMapping("/books")
    public Result boolist(){
         int m = 11/0;
        return new Result(200,"OK",true, this.bookFeignService.findBooks());
    }

    @GetMapping("/users")
    public Result userlist(){
        return new Result(200,"OK",true, this.userFeignService.findUser());
    }

    @PostMapping("/login")
    public Result login(@RequestParam("username")String username,@RequestParam("password")String password){
        return new Result(200,"OK",true, this.userFeignService.login(username,password));
    }
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user) {
        return new Result(200,"OK",true, this.userFeignService.save(user));
    }

    @GetMapping("/sms")
    public Result<Boolean> sendSms(@RequestParam("phone")String phone){
        return new Result<>(200,"OK",true,  this.smsFeignService.send(phone));
    }

    @GetMapping("/{username}")
    public Result hasUsername(@PathVariable("username") String username){
        return  this.userFeignService.hasName(username);
    }
}
